package com.company.servicename.util;

import com.company.servicename.enumerations.ResCodeEnum;

/**
 * @author fangsong.zhang
 * @date 2019/8/30 15:21
 * Copyright zfs
 * 类说明: 响应数据结构体
 * 用于统一API返回值，便于面向接口编程
 */
public class ResObject {
    /**
     * 返回码
     */
    private Integer code;
    /**
     * 返回消息
     */
    private String msg;
    /**
     * 返回数据
     */
    private Object data;
    /**
     * 是否展示
     */
    private Boolean showMsg = true;

    private ResObject(Integer code, String msg, Object data, Boolean showMsg) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.showMsg = showMsg;
    }

    private ResObject(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    private ResObject(Integer code, String msg, Boolean showMsg) {
        this.code = code;
        this.msg = msg;
        this.showMsg = showMsg;
    }

    private ResObject(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    private ResObject(String msg) {
        this.code = ResCodeEnum.SUCCESS.getKey();
        this.msg = msg;
    }

    private ResObject(Object data) {
        this.code = ResCodeEnum.SUCCESS.getKey();
        this.msg = ResCodeEnum.SUCCESS.getValue();
        this.data = data;
    }

    private ResObject() {
        this.code = ResCodeEnum.SUCCESS.getKey();
        this.msg = ResCodeEnum.SUCCESS.getValue();
    }

    public static ResObject success(String msg, Object data, Boolean showMsg) {
        return new ResObject(ResCodeEnum.SUCCESS.getKey(), msg, data, showMsg);
    }

    public static ResObject success(String msg, Object data) {
        return new ResObject(ResCodeEnum.SUCCESS.getKey(), msg, data);
    }

    public static ResObject success(String msg, Boolean showMsg) {
        return new ResObject(ResCodeEnum.SUCCESS.getKey(), msg, showMsg);
    }

    public static ResObject success(String msg) {
        return new ResObject(msg);
    }

    public static ResObject success(Object data) {
        return new ResObject(data);
    }

    public static ResObject success() {
        return new ResObject();
    }

    public static ResObject fail(String msg, Object data, Boolean showMsg) {
        return new ResObject(ResCodeEnum.FAIL.getKey(), msg, data, showMsg);
    }

    public static ResObject fail(String msg, Object data) {
        return new ResObject(ResCodeEnum.FAIL.getKey(), msg, data);
    }

    public static ResObject fail(String msg) {
        return new ResObject(ResCodeEnum.FAIL.getKey(), msg);
    }

    public static ResObject error(String msg, Object data, Boolean showMsg) {
        return new ResObject(ResCodeEnum.ERROR.getKey(), msg, data, showMsg);
    }

    public static ResObject error(String msg, Object data) {
        return new ResObject(ResCodeEnum.ERROR.getKey(), msg, data);
    }

    public static ResObject error(String msg) {
        return new ResObject(ResCodeEnum.ERROR.getKey(), msg);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Boolean getShowMsg() {
        return showMsg;
    }

    public void setShowMsg(Boolean showMsg) {
        this.showMsg = showMsg;
    }
}
